import Vue from 'vue'
import Router from 'vue-router'
import {count} from '@/assets/js/etherjs/wallet';
import store from "@/store/index";


function loadView(level, component) {
    return () => import(`@/${level}/${component}.vue`)
}

/* eslint-disable */
Vue.use(Router);

const router = new Router({
    routes: [
        {
            name: 'sign',
            path: '/',
            component: loadView('view', 'common/sign'),
            beforeEnter(to, from, next) {//before钩子函数，检测用户是否登录
                if (count() < 1) {
                    next();
                } else if (localStorage.getItem('touchId') == 1) {
                    // 跳转到指纹
                    next({path: '/touch'});
                } else {
                    next({path: '/index/wallet'});
                }

                // if (count() > 0) {
                //     next({path: '/index/wallet'});
                // }else{
                //     next()
                // }
            }
        },
        {
            name: 'index',
            path: '/index',
            component: loadView('view', 'index'),
            children: [
                // 钱包
                {
                    name: 'wallet',
                    path: 'wallet',
                    component: loadView('view', 'wallet/index'),
                },

                // 市场
                {
                    name: 'market',
                    path: 'market',
                    component: loadView('view', 'market/index'),
                },
                // dapp
                {
                    name: 'dapp',
                    path: 'dapp',
                    component: loadView('view', 'dapp/index'),
                },
                // 我
                {
                    name: 'my',
                    path: 'my',
                    component: loadView('view', 'my/index'),
                }
            ],
        },
        {
            name: 'language',
            path: '/language',
            component: loadView('view', 'common/language'),
        },
        {
            name: 'currency',
            path: '/currency',
            component: loadView('view', 'common/currency'),
        },
        {
            name: 'scan',
            path: '/scan',
            component: loadView('view', 'common/scan'),
        },
        {
            name: 'touch',
            path: '/touch',
            component: loadView('view', 'common/touch'),
        },
        {
            name: 'webview',
            path: '/webview',
            component: loadView('view', 'common/webview'),
        },
        ///////////////////////////////////////////////////钱包///////////////////////////////////////////////
        {
            name: 'wallet_create',
            path: '/wallet/create',
            component: loadView('view', 'wallet/create'),
        },
        {
            name: 'wallet_backup_tip',
            path: '/wallet/backup/tip',
            component: loadView('view', 'wallet/backup/tip'),
        },
        {
            name: 'wallet_backup_mnemonic',
            path: '/wallet/backup/mnemonic',
            component: loadView('view', 'wallet/backup/mnemonic'),
        },
        {
            name: 'wallet_backup_verify',
            path: '/wallet/backup/verify',
            component: loadView('view', 'wallet/backup/verify'),
        },
        {
            name: 'wallet_backup_tip',
            path: '/wallet/backup/tip',
            component: loadView('view', 'wallet/backup/tip'),
        },
        {
            name: 'wallet_qrcode',
            path: '/wallet/qrcode',
            component: loadView('view', 'wallet/qrcode'),
        },
        {
            name: 'wallet_list',
            path: '/wallet/list',
            component: loadView('view', 'wallet/list'),
        },

        // 钱包管理、
        {
            name: 'wallet_manager_index',
            path: '/wallet/manager/index',
            component: loadView('view', 'wallet/manager/index'),
        },
        {
            name: 'wallet_manager_private',
            path: '/wallet/manager/private',
            component: loadView('view', 'wallet/manager/private'),
        },
        {
            name: 'wallet_manager_keystore',
            path: '/wallet/manager/keystore',
            component: loadView('view', 'wallet/manager/keystore'),
        },
        {
            name: 'wallet_import',
            path: '/wallet/import',
            component: loadView('view', 'wallet/import'),
        },
        {
            name: 'wallet_import_scan',
            path: '/wallet/importScan',
            component: loadView('view', 'wallet/importScan'),
        },
        // 交易
        {
            name: 'wallet_transaction_etsc_list',
            path: '/wallet/transaction/etsc/list',
            component: loadView('view', 'wallet/transaction/etsc/list'),
        },
        {
            name: 'wallet_transaction_etsc_transfer',
            path: '/wallet/transaction/etsc/transfer',
            component: loadView('view', 'wallet/transaction/etsc/transfer'),
        },
        {
            name: 'wallet_transaction_etsc_detail',
            path: '/wallet/transaction/etsc/detail',
            component: loadView('view', 'wallet/transaction/etsc/detail'),
        },
        {
            name: 'wallet_transaction_eth_list',
            path: '/wallet/transaction/eth/list',
            component: loadView('view', 'wallet/transaction/eth/list'),
        },
        {
            name: 'wallet_transaction_eth_transfer',
            path: '/wallet/transaction/eth/transfer',
            component: loadView('view', 'wallet/transaction/eth/transfer'),
        },
        {
            name: 'wallet_transaction_eth_detail',
            path: '/wallet/transaction/eth/detail',
            component: loadView('view', 'wallet/transaction/eth/detail'),
        },
        {
            name: 'wallet_transaction_receive',
            path: '/wallet/transaction/receive',
            component: loadView('view', 'wallet/transaction/receive'),
        },

        ///////////////////////////////////////////////////dapp///////////////////////////////////////////////
        {
            name: 'sicbo',
            path: '/dapp/sicbo',
            component: loadView('view', 'dapp/sicbo/index'),
            children: [
                // 钱包
                {
                    name: 'bet',
                    path: 'bet',
                    component: loadView('view', 'dapp/sicbo/bet'),
                },
                // 市场
                {
                    name: 'count',
                    path: 'count',
                    component: loadView('view', 'dapp/sicbo/count'),
                },
            ],
        },
        /////E_Fomo/////
        {
            name: 'efomo',
            path: '/dapp/efomo',
            component: loadView('view', 'dapp/efomo/index'),
            children: [, {
                name: 'biling',
                path: 'biling',
                component: loadView('view', 'dapp/efomo/biling')
            }, {
                name: 'invite',
                path: 'invite',
                component: loadView('view', 'dapp/efomo/invite')
            }, {
                name: 'income',
                path: 'income',
                component: loadView('view', 'dapp/efomo/income')
            }, {
                name: 'lottery',
                path: 'lottery',
                component: loadView('view', 'dapp/efomo/lottery')
            }]
        },
        {
            name: 'register',
            path: '/dapp/efomo/register',
            component: loadView('view', 'dapp/efomo/register')
        },
        {
            name: 'fomoScan',
            path: '/dapp/efomo/fomoScan',
            component: loadView('view', 'dapp/efomo/fomoScan')
        },
        ///////////////////////////////////////////////////我的///////////////////////////////////////////////
        {
            name: 'my_contact_list',
            path: '/my/contact/list',
            component: loadView('view', 'my/contact/list'),
        },
        {
            name: 'my_contact_edit',
            path: '/my/contact/edit',
            component: loadView('view', 'my/contact/edit'),
        },
        {
            name: 'my_contact_add',
            path: '/my/contact/add',
            component: loadView('view', 'my/contact/add'),
        },
        {
            name: 'my_msg_list',
            path: '/my/msg/list',
            component: loadView('view', 'my/msg/list'),
        },
        {
            name: 'my_msg_detail',
            path: '/my/msg/detail',
            component: loadView('view', 'my/msg/detail'),
        },
        {
            name: 'my_about',
            path: '/my/about',
            component: loadView('view', 'my/about'),
        },
        {
            name: 'my_set',
            path: '/my/set',
            component: loadView('view', 'my/set'),
        },
        {
            name: 'my_agreement',
            path: '/my/agreement',
            component: loadView('view', 'my/agreement'),
        },
        {
            name: 'my_identity',
            path: '/my/identity',
            component: loadView('view', 'my/identity'),
        },
    ]
});

router.beforeEach((to, from, next) => {
    store.dispatch('aBackUrl', "");
    next();
});

export default router;